package cool.tianyou.blue.bird.config;

import cool.tianyou.blue.bird.common.model.po.LoginUser;
import java.util.List;
import javax.annotation.PostConstruct;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

/**
 * AuthConfiguration
 *
 * @author likeguo
 */
@Data
@Slf4j
@Configuration
@ConfigurationProperties("syncsms.auth")
public class AuthConfiguration {

    /**
     * 是否开启mock模式
     */
    @Value("${syncsms.auth.is-mock:false}")
    private boolean isMock;

    /**
     * 开启mock模式后模拟登录的用户
     */
    private LoginUser mockUser;

    /**
     * 登录及没次请求后登录续期时长
     */
    @Value("${syncsms.auth.renew-time:7200000}")
    private long renewTime;

    /**
     * 认证拦截排除路径
     */
    @Value("${syncsms.auth.auth-exclusion-paths:#{'/auth/login,/img/**,/login,auth/qrcode'.split(',')}}")
    private List<String> authExclusionPaths;

    @PostConstruct
    public void init() {
        log.info("auth configuration is 【{}】", this);
        if (isMock && mockUser == null) {
            throw new IllegalArgumentException("当前环境为开发环境，系统开启登录mock，但未正确配置mock登录但用户信息");
        }
    }
}
